package com.hnguigu.health.houduan.lq.service_lq.impl;

import com.hnguigu.health.houduan.lq.service_lq.TUserPsychologicalEvaluationService;
import com.hnguigu.health.mapper.TPhysicalEvaluationTableMapper;
import com.hnguigu.health.mapper.TUserPsychologicalEvaluationMapper;
import com.hnguigu.health.pojo.TPhysicalEvaluationTable;
import com.hnguigu.health.pojo.TPhysicalTable;
import com.hnguigu.health.pojo.TUserConstitutionTable;
import com.hnguigu.health.pojo.TUserPsychologicalEvaluation;
import com.hnguigu.health.utils.RequseionallAnswer;
import com.hnguigu.health.utils.UserContionXz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TUserPsychologicalEvaluationServiceImpl implements TUserPsychologicalEvaluationService {
    @Autowired(required = false)
    TUserPsychologicalEvaluationMapper tUserPsychologicalEvaluationMapper;
    @Autowired(required = false)
    TPhysicalEvaluationTableMapper tPhysicalEvaluationTableMapper;
    @Override
    public int addUserEvaluationConstitution(UserContionXz userContionXz) {
        return tUserPsychologicalEvaluationMapper.addUserEvaluationConstitution(userContionXz);
    }

    @Override
    public Map<Integer, List<RequseionallAnswer>> selectAllTUserEvaluationConstitution(String tMerBerid) {
        Map<Integer,List<RequseionallAnswer>> map=new HashMap<>();
        List<TPhysicalEvaluationTable> tPhysicalTables = tPhysicalEvaluationTableMapper.selectTphysicalEvaluation();
        List<TUserPsychologicalEvaluation> tUserConstitutionTables = tUserPsychologicalEvaluationMapper.selectAllTUserEvaluationConstitution(tMerBerid);
        for (TPhysicalEvaluationTable tPhysicalEvaluationTable : tPhysicalTables) {
            List<RequseionallAnswer> aa=new ArrayList<>();
            for (TUserPsychologicalEvaluation tUserConstitutionTable : tUserConstitutionTables) {
                RequseionallAnswer answer=new RequseionallAnswer();
                if(tUserConstitutionTable.gettUserPhysiqueId()==tPhysicalEvaluationTable.getTEvaluationId()){
                    answer.setId(tUserConstitutionTable.gettUserChooseEvaluationId());
                    answer.setVal(tUserConstitutionTable.gettUserChooseValue());
                    aa.add(answer);
                }
            }
            map.put(tPhysicalEvaluationTable.getTEvaluationId(),aa);
        }

        return map;
    }

    @Override
    public int deleteByTmerber(String tmerber) {
        return tUserPsychologicalEvaluationMapper.deleteByTmerber(tmerber);
    }

    @Override
    public TUserPsychologicalEvaluation tpbyTmerberLast(String tmerber) {
        List<TUserPsychologicalEvaluation> tUserPsychologicalEvaluations = tUserPsychologicalEvaluationMapper.selectAllTUserEvaluationConstitution(tmerber);

        return tUserPsychologicalEvaluations.get(tUserPsychologicalEvaluations.size()-1);
    }
}
